//
//  DetailCommentTableViewCell.m
//  TestApplication
//
//  Created by Hanlingyu on 16/9/8.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "DetailCommentTableViewCell.h"
#import "HomeChanneldetailCommentModel.h"

#import "TAMacro.h"
#import "SelfSizeTool.h"

#import "DetailCommentWithOtherTableViewCell.h"

@interface DetailCommentTableViewCell ()

<
UITableViewDelegate,
UITableViewDataSource
>
@property (nonatomic, strong) UITableView *commentTableView;
@property (nonatomic, strong) UIImageView *commentImage;


@end
@implementation DetailCommentTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        self.contentView.backgroundColor = [UIColor colorWithWhite:0.917 alpha:1.000];
        [self createView];
        
    }
    return self;
}

- (void)createView {
    
    _commentImage = [[UIImageView alloc] init];
    _commentImage.image = [UIImage imageNamed:@"addCommentList"];
    [self.contentView addSubview:_commentImage];
    
    _commentTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _commentTableView.backgroundColor = [UIColor yellowColor];
    _commentTableView.delegate = self;
    _commentTableView.dataSource = self;
    [_commentTableView registerNib:[UINib nibWithNibName:@"DetailCommentWithOtherTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"DetailCommentWithOtherTableViewCellReuse"];
    [self.contentView addSubview:_commentTableView];
    
    
    _commentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _commentTableView.scrollEnabled = NO;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    HomeChanneldetailCommentModel *commentModel = _commentArray[indexPath.row];
    if (commentModel.replyName) {
        NSString *string = [NSString stringWithFormat:@"回复 %@: %@", commentModel.replyName, commentModel.content];
        CGFloat height = [SelfSizeTool selfSizeHeightWithString:string width:SCREEN_WIDTH - 100 font:[UIFont systemFontOfSize:13]];
        return height + 35;
    } else {
        NSString *string = commentModel.content;
        CGFloat height = [SelfSizeTool selfSizeHeightWithString:string width:SCREEN_WIDTH - 100 font:[UIFont systemFontOfSize:13]];
        return height + 35;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    NSLog(@"%ld", _commentArray.count);
    return _commentArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailCommentWithOtherTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailCommentWithOtherTableViewCellReuse"];
    cell.commentModel = _commentArray[indexPath.row];
    
    return cell;
}
//#warning 页面跳转
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  {
//    NSLog(@"跳转页面cell");
//}

- (void)setCommentArray:(NSArray<HomeChanneldetailCommentModel *> *)commentArray {
    _commentArray = commentArray;
    [_commentTableView reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _commentTableView.frame = CGRectMake(45, 0, self.contentView.bounds.size.width - 60, self.contentView.bounds.size.height);
    _commentImage.frame = CGRectMake(17, 25, 15, 15);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
